package pendingFeatureCode

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"time"
)

type SSEHandler struct {
}

func streamSSE(c *gin.Context) {
	c.Writer.Header().Set("Content-Type", "text/event-stream")
	c.Writer.Header().Set("Cache-Control", "no-cache")
	c.Writer.Header().Set("Connection", "keep-alive")
	c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
	
	ticker := time.NewTicker(2 * time.Second)
	defer ticker.Stop()
	for {
		select {
		case <-c.Request.Context().Done():
			return
		case <-ticker.C:
			message := "data: " + time.Now().Format(time.RFC3339) + "\n\n"
			c.Writer.Write([]byte(message))
			c.Writer.(http.Flusher).Flush()
		}
	}
}
